function SwitchDemo() {
    this.sectorTitles = {
        "telco": "telecommunications",
        "utilities": "utilities",
        "resource": "natural resources",
        "government": "state and local government",
        "financial": "banking and financial services"
    };



    this.isOpen = false;

    this.jDiv = null;
    this.jIndustryName = null;
    this.jDemoButtons = null;
    this.jIndustryButtons = null;

    this.init = function () {

        this.sectorDemoTitles = {
            "telco": [demojson.titles.telco1, demojson.titles.telco2, demojson.titles.telco3],
            "utilities": [demojson.titles.utilities1, demojson.titles.utilities2],
            "resource": [demojson.titles.resource1, demojson.titles.resource2],
            "government": [demojson.titles.government1, demojson.titles.government2],
            "financial": [demojson.titles.financial1, demojson.titles.financial2]
        };
        var pageTracker = _gat._getTrackerByName();
        var marketoUrl = demojson.marketoUrl;
        var talkToUs = demojson.titles.talktous;

        if ($.getUrlVar('utm_source') != undefined) {
            marketoUrl += "?utm_source=" + $.getUrlVar('utm_source').replace(/#.*/, "");
            if ($.getUrlVar('utm_medium') != undefined) {
                marketoUrl += "&utm_medium=" + $.getUrlVar('utm_medium').replace(/#.*/, "");
            }
            if ($.getUrlVar('utm_term') != undefined) {
                marketoUrl += "&utm_term=" + $.getUrlVar('utm_term').replace(/#.*/, "");
            }
            if ($.getUrlVar('utm_content') != undefined) {
                marketoUrl += "&utm_content=" + $.getUrlVar('utm_content').replace(/#.*/, "");
            }
            if ($.getUrlVar('utm_campaign') != undefined) {
                marketoUrl += "&utm_campaign=" + $.getUrlVar('utm_campaign').replace(/#.*/, "");
            }
        }
        marketoUrl = pageTracker._getLinkerUrl(marketoUrl);
        this.jDiv = $('<div style="overflow:hidden;">' +
                        '<center>' +
                            '<table style="width:100%;">' +
                                '<tr>' +
                                    '<td style="background:white;width:345px;">' +
                                        '<span class="redText">' + talkToUs + '</span>' +
                                        '<iframe id="switch_form_frame" style="width:345px;height:535px;overflow-x:hidden;overflow-y:auto;border:none;" src="' + marketoUrl + '"></iframe>' +
                                    '</td>' +
                                    '<td style="background:white;">' +
                                        '<center>' +
                                            '<div style="vertical-align:middle;margin-top:64px;">' +
                                                '<center>' +
                                                    demojson.buttons.tryanother + '<br/><br/>' +
                                                    '<div id="switch_demo_buttons" style="vertical-align:top;">(buttons)</div>' +
                                                    '<div id="bottom_content">' +
                                                    	'<br/>' + demojson.titles.browse + '<br/><br/>' +
                                                    	'<div id="switch_industry_buttons">(buttons)</div>' +
                                                    '</div>' +
                                                '</center>' +
                                            '</div>' +
                                        '</center>' +
                                    '</td>' +
                                '</tr>' +
                            '</table>' +
                        '</center>' +
                    '</div>');
        $('body').append(this.jDiv);
        this.jDiv.dialog({ dialogClass: 'noTitle', width: 937, height: 591, resizable: false, zIndex: 10000, position: ['center', 'center'], closeOnEscape: false, autoOpen: false });

        _gaq.push(['_trackEvent', '(' + currentSector + currentSectorNumber + ') Demo contact form overlay', 'Form Load', 'Submit contact form']);
    };

    this.show = function () {
        switchDemoUI.jDiv.dialog('open');
        $('#switch_form_frame').show();
        this.isOpen = true;
    };

    this.hide = function () {
        switchDemoUI.jDiv.dialog('close');
        $('#switch_form_frame').hide();
        this.isOpen = false;
    };

    this.setDemo = function (sector, number) {
        var html = null;
        this.jIndustryName = $('#switch_industry_name');
        this.jDemoButtons = $('#switch_demo_buttons');
        this.jIndustryButtons = $('#switch_industry_buttons');
        this.jBottomContent = $('#bottom_content');

        // Industry title
        this.jIndustryName.html(this.sectorTitles[sector]);

        // Demo buttons
        html = "";
        if (sector == "telco") {
            if (number == -1) {
                html += this.createDemoButton(sector, 1, false);
                html += this.createDemoButton(sector, 2, false);
            } else if (number == 1) {
                html += this.createDemoButton(sector, 2, false);
                html += this.createDemoButton(sector, number, true);
            } else if (number == 2) {
                html += this.createDemoButton(sector, 1, false);
                html += this.createDemoButton(sector, number, true);
            } else if (number == 3) {
                //html += this.createDemoButton(sector, 1, false);
                //html += this.createDemoButton(sector, number, true);
            }
        } else if (sector == "utilities") {
            if (number == -1) {
                html += this.createDemoButton(sector, 1, false);
                html += this.createDemoButton(sector, 2, false);
            } else if (number == 1) {
                html += this.createDemoButton(sector, 2, false);
                html += this.createDemoButton(sector, number, true);
            } else if (number == 2) {
                html += this.createDemoButton(sector, 1, false);
                html += this.createDemoButton(sector, number, true);
            }
            if (number == 1) {
            } else if (number == 2) {
            }
        } else if (sector == "resource") {
            if (number == -1) {
                html += this.createDemoButton(sector, 1, false);
                html += this.createDemoButton(sector, 2, false);
            } else if (number == 1) {
                html += this.createDemoButton(sector, 2, false);
                html += this.createDemoButton(sector, number, true);
            } else if (number == 2) {
                html += this.createDemoButton(sector, 1, false);
                html += this.createDemoButton(sector, number, true);
            }
            if (number == 1) {
            } else if (number == 2) {
            }
        } else if (sector == "government") {
            if (number == -1) {
                html += this.createDemoButton(sector, 1, false);
                html += this.createDemoButton(sector, 2, false);
            } else if (number == 1) {
                html += this.createDemoButton(sector, 2, false);
                html += this.createDemoButton(sector, number, true);
            } else if (number == 2) {
                html += this.createDemoButton(sector, 1, false);
                html += this.createDemoButton(sector, number, true);
            }
        } else if (sector == "financial") {
            if (number == -1) {
                html += this.createDemoButton(sector, 1, false);
                //html += this.createDemoButton(sector, 2, false);
            } else if (number == 1) {
                //html += this.createDemoButton(sector, 2, false);
                html += this.createDemoButton(sector, number, true);
            } else if (number == 2) {
                html += this.createDemoButton(sector, 1, false);
                //html += this.createDemoButton(sector, number, true);
            }
        }
        this.jDemoButtons.html(html);

        // Industry buttons
        html = "";
        if (window.location.href.indexOf(".co.in") > -1 && calendarJson != null || ($.getUrlVar('country') != undefined && $.getUrlVar('country').replace(/#.*/, "") == "in")) {
            if (calendarJson.indonesia.hasOwnProperty(sector)) {
                var date;
                switch (sector) {
                    case "government":
                        date = new Date(calendarJson.indonesia.government.year, calendarJson.indonesia.government.month, calendarJson.indonesia.government.day);
                        if (date > new Date()) { // event date is in the future
                            html = "<br/>Discover more at our upcoming State &amp; Local Government event<br/><br/>" +
	        						'<a href="' + calendarJson.indonesia.government.link + '" style="outline:none"><img src="/img/tiles/register-now.png" alt="Register Now" /></a><br/><br/>' +
	        						'<a href="/" style="text-decoration:none;background:url(/img/icons/goback.png) right top no-repeat;padding-right:30px;height:37px;line-height:37px;display:inline-block;*display:block;*zoom:1">Return home and continue exploring</a>';
                        }
                        else {
                            this.jIndustryButtons.html(this.createIndustryButtons(sector, this.sectorTitles));
                        }
                        break;
                }
                if (html != "")
                    this.jBottomContent.html(html);
            }
        }
        else if (window.location.href.indexOf(".com.au") > -1 && calendarJson != null || ($.getUrlVar('country') != undefined && $.getUrlVar('country').replace(/#.*/, "") == "au")) {
            if (calendarJson.australia.hasOwnProperty(sector)) {
                var date;
                switch (sector) {
                    case "telco":
                        date = new Date(calendarJson.australia.telco.year, calendarJson.australia.telco.month, calendarJson.australia.telco.day);
                        if (date > new Date()) { // event date is in the future
                            html = '<br/>Discover more at our upcoming Telecommunications event<br/><br/>' +
	        					   '<a href="' + calendarJson.australia.telco.link + '" style="outline:none"><img src="/img/tiles/register-now.png" alt="Register Now" /></a><br/><br/>' +
	        					   '<a href="/" style="text-decoration:none;background:url(/img/icons/goback.png) right top no-repeat;padding-right:30px;height:37px;line-height:37px;display:inline-block;*display:block;*zoom:1">Return home and continue exploring</a>';
                        }
                        else {
                            this.jIndustryButtons.html(this.createIndustryButtons(sector, this.sectorTitles));
                        }
                        break;
                    case "utilities":
                        date = new Date(calendarJson.australia.utilities.year, calendarJson.australia.utilities.month, calendarJson.australia.utilities.day);
                        if (date > new Date()) { // event date is in the future
                            html = "<br/>Discover more at our upcoming Utilities event<br/><br/>" +
	        						'<a href="' + calendarJson.australia.utilities.link + '" style="outline:none"><img src="/img/tiles/register-now.png" alt="Register Now" /></a><br/><br/>' +
	        						'<a href="/" style="text-decoration:none;background:url(/img/icons/goback.png) right top no-repeat;padding-right:30px;height:37px;line-height:37px;display:inline-block;*display:block;*zoom:1">Return home and continue exploring</a>';
                        }
                        else {
                            this.jIndustryButtons.html(this.createIndustryButtons(sector, this.sectorTitles));
                        }
                        break;
                    case "resource":
                        date = new Date(calendarJson.australia.resource.year, calendarJson.australia.resource.month, calendarJson.australia.resource.day);
                        if (date > new Date()) { // event date is in the future
                            html = "<br/>Discover more at our upcoming Natural Resources event<br/><br/>" +
	        						'<a href="' + calendarJson.australia.resource.link + '" style="outline:none"><img src="/img/tiles/register-now.png" alt="Register Now" /></a><br/><br/>' +
	        						'<a href="/" style="text-decoration:none;background:url(/img/icons/goback.png) right top no-repeat;padding-right:30px;height:37px;line-height:37px;display:inline-block;*display:block;*zoom:1">Return home and continue exploring</a>';
                        }
                        else {
                            this.jIndustryButtons.html(this.createIndustryButtons(sector, this.sectorTitles));
                        }
                        break;
                    case "government":
                        date = new Date(calendarJson.australia.government.year, calendarJson.australia.government.month, calendarJson.australia.government.day);
                        if (date > new Date()) { // event date is in the future
                            html = "<br/>Discover more at our upcoming State &amp; Local Government event<br/><br/>" +
	        						'<a href="' + calendarJson.australia.government.link + '" style="outline:none"><img src="/img/tiles/register-now.png" alt="Register Now" /></a><br/><br/>' +
	        						'<a href="/" style="text-decoration:none;background:url(/img/icons/goback.png) right top no-repeat;padding-right:30px;height:37px;line-height:37px;display:inline-block;*display:block;*zoom:1">Return home and continue exploring</a>';
                        }
                        else {
                            this.jIndustryButtons.html(this.createIndustryButtons(sector, this.sectorTitles));
                        }
                        break;
                    case "financial":
                        date = new Date(calendarJson.australia.financial.year, calendarJson.australia.financial.month, calendarJson.australia.financial.day);
                        if (date > new Date()) { // event date is in the future
                            html = "<br/>Discover more at our upcoming Banking &amp; Financial event<br/><br/>" +
	        						'<a href="' + calendarJson.australia.financial.link + '" style="outline:none"><img src="/img/tiles/register-now.png" alt="Register Now" /></a><br/><br/>' +
	        						'<a href="/" style="text-decoration:none;background:url(/img/icons/goback.png) right top no-repeat;padding-right:30px;height:37px;line-height:37px;display:inline-block;*display:block;*zoom:1">Return home and continue exploring</a>';
                        }
                        else {
                            this.jIndustryButtons.html(this.createIndustryButtons(sector, this.sectorTitles));
                        }
                        break;
                }
                if (html != "")
                    this.jBottomContent.html(html);
            }
            else {
                this.jIndustryButtons.html(this.createIndustryButtons(sector, this.sectorTitles));
            }
        }
        else {
            this.jIndustryButtons.html(this.createIndustryButtons(sector, this.sectorTitles));
        }


    };

    this.createDemoButton = function (sector, number, isRepeat) {
        
        if (isRepeat) {
            return '<div onclick="loadSubDemo(\'' + sector + '\',' + number + ');return true;" style="display:inline-block;cursor:pointer;width:166px;margin:7px 7px;text-align:center;vertical-align:top;"><img src="' + getImageLocation('demo_repeat.png') + '"/><br/>' + this.sectorDemoTitles[sector][number - 1] + '</div>';
        } else if (number == 1) {
            return '<div onclick="loadSubDemo(\'' + sector + '\',' + number + ');return true;" style="display:inline-block;cursor:pointer;width:166px;margin:7px 7px;text-align:center;vertical-align:top;"><img src="' + getImageLocation('demo_one.png') + '"/><br/>' + this.sectorDemoTitles[sector][number - 1] + '</div>';
        } else if (number == 2) {
            return '<div onclick="loadSubDemo(\'' + sector + '\',' + number + ');return true;" style="display:inline-block;cursor:pointer;width:166px;margin:7px 7px;text-align:center;vertical-align:top;"><img src="' + getImageLocation('demo_two.png') + '"/><br/>' + this.sectorDemoTitles[sector][number - 1] + '</div>';
        } else if (number == 3) {
            return '<div onclick="loadSubDemo(\'' + sector + '\',' + number + ');return true;" style="display:inline-block;cursor:pointer;width:166px;margin:7px 7px;text-align:center;vertical-align:top;"><img src="' + getImageLocation('demo_three.png') + '"/><br/>' + this.sectorDemoTitles[sector][number - 1] + '</div>';
        }
    }

    this.createIndustryButton = function (sector) {
        
        return '<img style="cursor:pointer;margin:7px;" src="img/' + ((language == undefined) ? "" : language + '/') + 'small_tiles/' + sector + '.png" onclick="loadSubDemo(\'' + sector + '\',' + 1 + ');return true;"/>';
    }

    this.createIndustryButtons = function (sector, sectorTitles) {
        html = "";
        for (var key in sectorTitles) {
            if (key == sector) continue;
            html += this.createIndustryButton(key);
        }
        return html;
    }
}
